package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.TApplication;
import cn.stylefeng.guns.modular.system.mapper.TApplicationMapper;
import cn.stylefeng.guns.modular.system.model.params.TApplicationParam;
import cn.stylefeng.guns.modular.system.model.result.TApplicationResult;
import  cn.stylefeng.guns.modular.system.service.TApplicationService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 *    退款申请
 * </p>
 *
 * @author yl
 * @since 2019-07-09
 */
@Service
public class TApplicationServiceImpl extends ServiceImpl<TApplicationMapper, TApplication> implements TApplicationService {

    @Autowired
    private TApplicationMapper tApplicationMapper;


    @Override
    public void add(TApplicationParam param){
        TApplication entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TApplicationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TApplicationParam param){
        TApplication oldEntity = getOldEntity(param);
        TApplication newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TApplicationResult findBySpec(TApplicationParam param){
        return null;
    }

    @Override
    public List<TApplicationResult> findListBySpec(TApplicationParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TApplicationParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TApplicationParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TApplication getOldEntity(TApplicationParam param) {
        return this.getById(getKey(param));
    }

    private TApplication getEntity(TApplicationParam param) {
        TApplication entity = new TApplication();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


    @Override
    public List<TApplication> QueryListLiftJoin(String condition){
        return tApplicationMapper.QueryListLiftJoin(condition);
    }


    /**
     * 查询详情
     */
    @Override
    public TApplication QueryId(@Param("id") String id){
        return tApplicationMapper.QueryId(id);
    }


    /**
     * 修改接口
     */
    @Override
    public String UpdateApplicationId(String type, String remoney, String enclosu, String order_id, String remarks, Integer id){
        return tApplicationMapper.UpdateApplicationId(type,remoney,enclosu,order_id,remarks,id);
    }

    @Override
    public TApplication getByProcessInstanceId(String processInstanceId) {
        return this.baseMapper.getByProcessInstanceId(processInstanceId);
    }


}
